﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebTemplate.DAL.Entities;

namespace WebTemplate.DAL.Repositories
{
  public  class CourseDetailsRepository
    {
      public List<CourseDetails> Select(CourseDetailsSearchCriteria item)
      {
          SqlConnection connection = new SqlConnection();
          connection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

          SqlCommand command = new SqlCommand();
          command.Connection = connection;
          command.CommandText = "[CourseDetails_Select]";
          command.CommandType = System.Data.CommandType.StoredProcedure;
          command.Parameters.AddWithValue("@CourseSemesterId", item.CourseSemesterId);


          connection.Open();

          SqlDataReader reader = command.ExecuteReader();

          List<CourseDetails> lst = new List<CourseDetails>();
          while (reader.Read())
          {
              CourseDetails obj = new CourseDetails();

              obj.CourseName = reader.GetString(0);
              obj.MemberFirstName = reader.GetString(1);
              obj.MemberLastName = reader.GetString(2);
              obj.Lecture = reader.GetString(3);
              obj.Time = reader.GetDateTime(4);
              obj.CourseSemesterId = reader.GetInt32(5);
         

              lst.Add(obj);
          }
          connection.Close();

          return lst;
      }
    }
}
